<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateEditProjectTable extends AbstractMigration
{
    public function up()
    {
        $this->table('edit_project', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '剪辑工程'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('project_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '项目id'])
            ->addColumn('tenant_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '租户id'])
            ->addColumn('episode_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '剧集id'])
            ->addColumn('name', 'string', ['null' => false, 'default' => '', 'limit' => 11, 'comment' => '剧集id'])
            ->addColumn('description', 'text', ['null' => true, 'comment' => '描述'])
            ->addColumn('json', 'json', ['null' => true, 'comment' => '存储自定义字段'])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间',])
            ->addColumn('created_by', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建人',])
            ->addColumn('updated', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '更新时间',])
            ->addColumn('updated_by', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '更新人',])
            ->addIndex(['project_id', 'episode_id'], ['type' => 'normal', 'name' => 'idx_project_episode'])
            ->save();;
    }

    public function down()
    {
        $this->table('edit_project')->drop()->save();
    }
}
